﻿using BLL;
using DAL;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Model;
using System.Collections.Generic;

namespace TiboShop.Controllers
{
    public class MallController : Controller
    {
		private readonly ISession _session;
		private readonly IHttpContextAccessor _contextAccessor;
		private readonly BLLCommodity commodity;
        public MallController(BLLCommodity com, IHttpContextAccessor accessor)
		{
			_contextAccessor = accessor;
			_session = _contextAccessor.HttpContext!.Session;
            commodity = com;
        }
        [HttpGet]
        public IActionResult Index()
        {
			ViewBag.role = Convert.ToInt32(_session.GetInt32("URID"));
			List<Commodity> commodities = new List<Commodity>();
            commodities = commodity.GetAllCommodity();
            return View(commodities);
        }
        [HttpGet]
        public IActionResult Indext(List<Commodity> ls)
        {
            ViewBag.role = Convert.ToInt32(_session.GetInt32("URID"));
            return View(ls);
        }
        public IActionResult CheckCommodityByifo(string searchvalue)
        {
            List<Commodity> commodities = commodity.CheckCommodityByifo(searchvalue)!;
            ViewBag.role = Convert.ToInt32(_session.GetInt32("URID"));
            return View(commodities);
        }

    }
}
